package com.systop.dxjj.modules.findteacher.service.impl;


import com.systop.dxjj.common.pojo.Findteacher;
import com.systop.dxjj.common.utils.R;
import com.systop.dxjj.modules.findteacher.mapper.FindteacherMapper;
import com.systop.dxjj.modules.findteacher.service.FindteacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 吴健伟
 */
@Service
public class FindteacherServiceImpl implements FindteacherService {

    @Autowired
    private FindteacherMapper findteacherMapper;


    @Override
    public R selectAllTeacherInfo() {
        List<Findteacher> findteachers = findteacherMapper.selectAllTeacherInfo();
        return R.ok().put("findteachers",findteachers);
    }

    @Override
    public R insertTeacherInfo(Findteacher findteacher) {
        int num = findteacherMapper.insertFindteacher(findteacher);
        if (num > 0){
            return R.ok().put("msg","添加成功");
        }else {
            return R.ok().put("msg", "添加失败");
        }
    }

    @Override
    public R updateTeacherInfo(Findteacher findteacher) {
        int num = findteacherMapper.updateFindteacher(findteacher);
        if (num > 0){
            return R.ok().put("msg","修改成功");
        }else {
            return R.ok().put("msg", "修改失败");
        }
    }

    @Override
    public R delTeacherInfo(Integer id) {
        int num = findteacherMapper.deleteFindteacher(id);
        if (num > 0){
            return R.ok().put("msg","删除成功");
        }else {
            return R.ok().put("msg", "删除失败");
        }
    }

    @Override
    public R selectTeacherInfoByName(String name) {
        List<Findteacher> findteachers = findteacherMapper.selectTeacherInfoByName(name);
        return R.ok().put("name",findteachers);
    }

    @Override
    public R findByPage(Integer pageNum, Integer pageSize) {



        List<Findteacher> data = findteacherMapper.findByPage((pageNum - 1) * pageSize, pageSize);
        if (data != null && data.size() > 0) {

            return R.ok().put("data",data).put("code",200).put("msg","数据显示成功");
        } else {

            return R.ok().put("code",100).put("msg","暂时没有数据");
        }
    }
}
